DEFINE VARIABLE db AS CHARACTER.
DEFINE VARIABLE ldb AS CHARACTER.
DEFINE VARIABLE host AS CHARACTER.
DEFINE VARIABLE port AS CHARACTER.

ASSIGN db   = "mfghis".
ASSIGN ldb  = "qadhis".
ASSIGN host = "hkqadser".
ASSIGN port = "3830".

FUNCTION connectDB RETURNS LOGICAL (INPUT db AS CHARACTER,INPUT ldb AS CHARACTER,
                                    INPUT host AS CHARACTER, INPUT port AS CHARACTER).

    DEFINE VARIABLE sParam AS CHARACTER INITIAL "".          

    IF CONNECTED("""" + ldb + """") = TRUE THEN 
       RETURN (TRUE).
    
    sParam = " -db " + db + " -ld " + ldb + " -N TCP -H " + host + " -S " + port.

    CONNECT VALUE(sParam).
    IF ERROR-STATUS:ERROR = YES THEN 
       RETURN (FALSE).
    ELSE
       RETURN (TRUE).

END FUNCTION.


FUNCTION disconnectDB RETURNS LOGICAL (INPUT ldb AS CHARACTER).

    DISCONNECT VALUE(ldb) NO-ERROR.
    RETURN (TRUE).

END FUNCTION.


/* MESSAGE "connet =" connectDB ( db, ldb, host, port).       */
/* MESSAGE "disconnet =" disconnectDB ( db, ldb, host, port). */

